import requests
import jsonpath

url = "http://localhost:8000/api/v1/recognition/recognize"

api_key = "da6e54bd-e98c-4e3c-a787-107625f36e93"
file_path = "C:/Users/Haolin/Desktop/face/微信图片_20240413203941.jpg"

headers = {
    'x-api-key': api_key,
}

files = {
    'file': (file_path, open(file_path, 'rb'), 'image/jpeg'),
}


response = requests.post(url, headers=headers, files=files)

result1 = response.json()

subject_list = jsonpath.jsonpath(result1, '$..subject')
similarity_list = jsonpath.jsonpath(result1, '$..similarity')

print(subject_list , similarity_list)

def send_wechat(msg):
    token = '2cc51f9611034e5cb9614c5b948d3640'
    title = '人脸识别结果'
    content = msg
    template = 'html'
    url = f"https://www.pushplus.plus/send?token={token}&title={title}&content={content}&template={template}"
    print(url)
    r = requests.get(url=url)
    print(r.text)

if __name__ == '__main__':
    if  similarity_list[0] > 0.8:
        msg = subject_list[0]
        send_wechat(msg)
    else:
        msg = '陌生人'
        send_wechat(msg)